﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TPA.DataAccess;
using TVProgramAnalyst.Common;

namespace TVProgramAnalyst.TimeLine
{
    public partial class frmChannel : Form
    {
        bool _ChannelUpdated=false;

        public frmChannel()
        {
            InitializeComponent();
        }

        private void frmChannel_Load(object sender, EventArgs e)
        {
            dgvChannelList.DataSource = BLLFactory.ChannelBLL.GetAll();
            BLLFactory.ChannelBLL.Refresh();
            tabpageChannels.Text = "编辑频道";
        }

        private void dgvChannelList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void toolBtnSave_Click(object sender, EventArgs e)
        {
            BLLFactory.ChannelBLL.SaveChanges();
            tabpageChannels.Text = "编辑频道";
            _ChannelUpdated = false;
        }

        private void frmChannel_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_ChannelUpdated)
            {
                DialogResult result=MessageBox.Show("保存所有修改？", "保存", MessageBoxButtons.YesNoCancel);
                if (DialogResult.Yes ==result )
                {
                    BLLFactory.ChannelBLL.SaveChanges();
                    this.Dispose(true);
                }
                else if (DialogResult.No == result)
                {
                    this.Dispose(true);
                }
                else
                {

                }
            }
        }

        private void dgvChannelList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dgvChannelList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //propertyGrid1.SelectedObject = BLLFactory.ChannelBLL.Get(dgvChannelList.Rows[e.RowIndex].Cells[0].Value.ToString());
            frmProperty frm = frmProperty.PropertyFormInstance;
            frm.SelectedObject = BLLFactory.ChannelBLL.Get(dgvChannelList.Rows[e.RowIndex].Cells[0].Value.ToString());
            frm.ShowDialog(this);
            tabpageChannels.Text = "编辑频道*";
            _ChannelUpdated = true;
        }
    }
}
